<html>
<head><meta charset="utf-8"><title>confusion over chaining iter::once with another iterator · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html">confusion over chaining iter::once with another iterator</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236665106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665106">(Apr 29 2021 at 12:35)</a>:</h4>
<p>Dear all, It seems like doing something like iter::once(2).chain(other) yields an iterator that only returns one element</p>
<p>If this is not the case as it should not be, then why does the following test fail? : </p>
<p><a href="/user_uploads/4715/wVTO3S92akNWVPMWm0oPwrdE/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/wVTO3S92akNWVPMWm0oPwrdE/image.png" title="image.png"><img src="/user_uploads/4715/wVTO3S92akNWVPMWm0oPwrdE/image.png"></a></div>



<a name="236665259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Kądziołka <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665259">(Apr 29 2021 at 12:36)</a>:</h4>
<p>Please don't post code as image, that breaks copy paste</p>



<a name="236665350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665350">(Apr 29 2021 at 12:37)</a>:</h4>
<p>use std::iter;<br>
use std::u128;</p>
<p>pub fn is_square_free(n: u128) -&gt; bool {<br>
    !iter::once(2_u128)<br>
        .chain((3_128..n).into_iter().step_by(2))<br>
        .map(|i| i.pow(2))<br>
        .take_while(|i| i &lt;= &amp;n)<br>
        .any(|i| (n % i) == 0)<br>
}</p>
<p>#[cfg(test)]<br>
mod tests {<br>
    use super::*;<br>
    #[test]<br>
    fn not_square_free() {<br>
        assert!(!is_square_free(9));<br>
    }<br>
}</p>



<a name="236665373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665373">(Apr 29 2021 at 12:37)</a>:</h4>
<p>What if you do <code>n % dbg!(i) == 0</code>?</p>



<a name="236665436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665436">(Apr 29 2021 at 12:37)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dd874fdf2dd070601e0d160b75d462fe">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dd874fdf2dd070601e0d160b75d462fe</a></p>



<a name="236665576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665576">(Apr 29 2021 at 12:39)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b2126d660a18e059955395ca5b163da9">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b2126d660a18e059955395ca5b163da9</a></p>



<a name="236665631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236665631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236665631">(Apr 29 2021 at 12:39)</a>:</h4>
<p>It looks like only 4 is produced and it stops after that</p>



<a name="236666075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666075">(Apr 29 2021 at 12:43)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu</span>  did I manage to find a bug in Rust itself? Or am I misunderstanding something fundamental here (I hope it is the latter)</p>



<a name="236666223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666223">(Apr 29 2021 at 12:44)</a>:</h4>
<p>No, you have a typo</p>



<a name="236666242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666242">(Apr 29 2021 at 12:44)</a>:</h4>
<p>You want <code>3_u128</code>, not <code>3_128</code> (just <code>3</code> is fine though)</p>



<a name="236666326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666326">(Apr 29 2021 at 12:45)</a>:</h4>
<p>Ah. What does 3_128 do?</p>



<a name="236666360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666360">(Apr 29 2021 at 12:45)</a>:</h4>
<p>It's like <code>3128</code></p>



<a name="236666405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236666405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236666405">(Apr 29 2021 at 12:45)</a>:</h4>
<p>Ah, Ok thanks :) I love the Rust community!</p>



<a name="236704436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236704436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236704436">(Apr 29 2021 at 16:29)</a>:</h4>
<p>Oh, you got unlucky in that you're using <code>u128</code>.  For any other width of integer, clippy will help out this this:</p>
<div class="codehilite"><pre><span></span><code>error: mistyped literal suffix
 --&gt; src/main.rs:2:13
  |
2 |     let x = 3_32;
  |             ^^^^ help: did you mean to write: `3_i32`
  |
  = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes
</code></pre></div>



<a name="236705070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236705070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236705070">(Apr 29 2021 at 16:33)</a>:</h4>
<p>Clippy should probably lint for u128 too, no?</p>



<a name="236705107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236705107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236705107">(Apr 29 2021 at 16:34)</a>:</h4>
<p>Oh well I guess it could also not be a typo hmm</p>



<a name="236705389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236705389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236705389">(Apr 29 2021 at 16:35)</a>:</h4>
<p>Yeah, that's the problem.  When we looked it seemed like it was very uncommon to have <code>x_xx</code> -- there are some locales with <code>xx_xx_xxx</code>, but nothing I found that does <code>xx_xx_xx</code> -- but of course <code>3_789_128</code> is just as plausibly not a typo.</p>



<a name="236707778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236707778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236707778">(Apr 29 2021 at 16:51)</a>:</h4>
<p>does clippy have enough type information to apply that contextually? that is, only warn about <code>..._128</code> if you use that in a context that is otherwise known to be <code>i128</code>/<code>u128</code> already</p>



<a name="236707801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236707801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236707801">(Apr 29 2021 at 16:51)</a>:</h4>
<p>but I don't know what the remedy would be if you really wanted the value, not a suffix</p>



<a name="236713405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236713405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236713405">(Apr 29 2021 at 17:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator/near/236707801">said</a>:</p>
<blockquote>
<p>but I don't know what the remedy would be if you really wanted the value, not a suffix</p>
</blockquote>
<p>Force the usage of the suffix anyway: <code>9_128_u32</code></p>



<a name="236714836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236714836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Kądziołka <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236714836">(Apr 29 2021 at 17:38)</a>:</h4>
<p>or <code>9_128_</code> if you don't want to specify the type</p>



<a name="236714873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/confusion%20over%20chaining%20iter%3A%3Aonce%20with%20another%20iterator/near/236714873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/confusion.20over.20chaining.20iter.3A.3Aonce.20with.20another.20iterator.html#236714873">(Apr 29 2021 at 17:38)</a>:</h4>
<p>that seems ugly though</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>